//
// Created by user on 2022/4/11.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    //超时
    int uniquePaths(int m, int n) {
        vector<vector<int>> meno(m, vector<int>(n, -1));
        return dfs(m,n,0,0, meno);
    }
    int dfs(int m, int n, int i, int j, vector<vector<int>> meno){
        if(m-1==i && n-1==j){
            return 1;
        }
        if (i == m || j == n) return 0;
        if(meno[i][j]!=-1)return meono[i][j];
        int left = dfs(m,n,i+1, j, meno);
        int right = dfs(m,n, i,j+1, meno);
        meno[i][j] = left+right;
        return meno[i][j];
    }
    //动态规划
    int uniquePaths1(int m, int n) {
       // 定义维度
        vector<vector<int>> dp(m, vector<int>(n));
        //一行
        for (int i = 0; i < m; ++i) {
            dp[i][0] = 1;
        }
        //一列
        for (int i = 0; i < n; ++i) {
            dp[0][i]=1;
        }
        for (int i = 1; i < m; ++i) {
            for (int j = 1; j < n; ++j) {
               dp[i][j] = dp[i-1][j]+dp[i][j-1];
            }
        }
        return dp[m-1][n-1];
    }
};